<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]
        // a. 获取数组中最大值、最小值
            const  max = Math.max(...arr);
            const min =  Math.min(...arr)
            console.log(max)//18
            console.log(min)//2


      //c. 求和
        const total = arr.reduce(function(prev,item){
        return prev + item
        } ,0)
        console.log(total)//106
        //b. 计算平均值
        const mean = total / arr.length
        console.log(mean)//平均数为: 7.571428571428571

     //d. 降序排序
        const lesson = arr.sort(function(a,b){
            return b-a
        })
        console.log(lesson)

// e.去重
        //思路准备一个新空数组，将需要去重的数组进行遍历，判断新数组中是否有当前元素，若没有，这push到新数组中
        //     const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]
        function unique(arr) {
        var newArr = [];
        for (var i = 0; i < arr.length; i++) {
        if (newArr.indexOf(arr[i]) === -1) {
            newArr.push(arr[i]);
        }
        }
        return newArr;
        }
    console.log(unique(arr))//得到数组array[5,3,2,8,11,18,6,10,12,14,7]
        </script>
    </body>
</html>